/*
 * @: 
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-10-19 00:12:43
 * @LastEditors: ziwei
 * @LastEditTime: 2021-11-01 17:17:28
 */
import * as actionType from '../action-types'
let actions = {
    add1(){
        return {type:actionType.ADD1}
    },
    minus1(){
        return {type:actionType.MINUS1}
    },
    changeColor(color){
        return {type:actionType.CHANGE_COLOR,payload:color}
    },
    thunkAdd(){
      return function(dispatch,getState) {
        setTimeout(()=>{
          dispatch({type:actionType.ADD1})
        },1000)  
      }
    },
    promiseAdd(){
      return new Promise((resolve,reject)=>{
        setTimeout(()=>{
          //只能处理成功不能处理失败
          resolve({type:actionType.ADD1})
        })
      })
    }
    //promise 第二种用法
    ,promise2Add(){
      return {
        type:actionType.ADD1,
        payload:new Promise((resolve,reject)=>{
          setTimeout(() => {
            let number = Math.random();
            if(number>=0.5){
              resolve(number);
            }else{
              reject(-1)
            }
          }, 1000);
        })
      }
    }
}
export default actions